/*
 *  Copyright (C) 2010 Matthias Buch-Kromann <mbk.isv@cbs.dk>
 * 
 *  This file is part of the IncrementalParser package.
 *  
 *  The IncrementalParser program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.osdtsystem.incparser.graphs;

/**
 *
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public class GraphOverlayRemoveEdge extends GraphOverlay {
    int layer;
    int innode;
    int outnode;
    int type;
    AbstractLocalGraph inNodeGraph;
    AbstractLocalGraph outNodeGraph;

    GraphOverlayRemoveEdge(AbstractGraph parentGraph, int layer, int innode, int outnode, int type) {
        // Call parent constructor and initialize variables
        super(parentGraph);
        this.layer = layer;
        this.innode = innode;
        this.outnode = outnode;
        this.type = type;

        // Create new local graphs
        this.inNodeGraph = super._localGraphRW(innode, layer).clone();
        this.outNodeGraph = super._localGraphRW(outnode, layer).clone();
        this.inNodeGraph.removeInEdge(Helper.pack(outnode, type));
        this.outNodeGraph.removeOutEdge(Helper.pack(innode, type));

        // Notify listeners
        baseGraph._notifyEdgeRemoved(this, layer, innode, outnode, type);
    }

    @Override
    public LocalGraph localGraph(int node, int layer) {
        if (node == innode && layer == this.layer)
            return inNodeGraph;
        if (node == outnode && layer == this.layer)
            return outNodeGraph;
        return
            super.localGraph(node, layer);
    }

    @Override
    void _writeGraphChangesToBaseGraphPreprocess() {
        baseGraph.removeEdge(layer, innode, outnode, type);
    }
}
